<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>welcome</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="__STATIC__/css/font.css">
    <link rel="stylesheet" href="__STATIC__/css/xadmin.css">
</head>
<body>
<div class="x-body layui-anim">
    <blockquote class="layui-elem-quote">
        <span  style="color: red;padding-left: 10px">统计不准确？</span>
        <a href="javascript:;" class="calibration">点击校准</a>
    </blockquote>
    <div class="layui-fluid">
        {if $_admin.id == 1}
        <div class="layui-row layui-col-space20 statistics" style="text-align: center; font-size: 16px;font-weight: bold;">
        {/if}
    </div>

</div>
<script id="template" type="text/html">
    {{# for(let x in d){ }}
    <div class="layui-col-xs12 layui-col-sm6 layui-col-md6" >
        <fieldset class="layui-elem-field">
            <legend>{{x}}</legend>
            <div class="layui-field-box">
                <div class="layui-row layui-col-space20">
                    <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                        <div class="layui-card-header layui-bg-blue">今日</div>
                        <div class="layui-card-body layui-bg-gray"> {{d[x].today}}</div>
                    </div>
                    <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                        <div class="layui-card-header layui-bg-green">本月</div>
                        <div class="layui-card-body layui-bg-gray"> {{d[x].month}}</div>
                    </div>
                    <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                        <div class="layui-card-header layui-bg-red">汇总</div>
                        <div class="layui-card-body layui-bg-gray"> {{d[x].sum}}</div>
                    </div>
                </div>
            </div>
        </fieldset>
    </div>
    {{# } }}
</script>
</body>
<script type="text/javascript" src="__STATIC__/js/jquery.min.js"></script>
<script type="text/javascript" src="__STATIC__/lib/layui/layui.js" charset="utf-8"></script>
<script>
    $(function () {

        var laytpl, layer;
        layui.use(['laytpl', 'layer'], function () {
            laytpl = layui.laytpl;
            layer = layui.layer;
            get_info()
        });

        $('.calibration').click(function () {
            layer.confirm('点击确认按钮开始校准统计', {title:'系统提示'},function (index) {
                let load = layer.msg('重新校准中...请耐心等待', {icon: 16,shade: 0.01,time:10000});
                $.ajax({
                    type: 'GET',
                    url: '{:url("index/calibration")}',
                    dataType: "json",
                    success: function (data) {
                        layer.close(load);
                        if (data.code === 1) {
                            layer.msg(data.msg, {time: 1000},function () {
                                location.reload();
                            });
                        }else{
                            layer.msg(data.msg);
                        }
                    }
                });
            });
        });

        function get_info() {
        	let load = layer.msg('加载中...', {icon: 16,shade: 0.01,time:10000});
            $.ajax({
                type: 'POST',
                url: '{:url("index/welcome")}',
                dataType: "json",
                success: function (data) {
                	layer.close(load);
                    if (data.code === 1) {
                        var tpl = document.getElementById('template').innerHTML;
                        laytpl(tpl).render(data.result, function (html) {
                            $('.statistics').prepend(html);
                        });
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });
        }
    });
</script>
</html>